 <%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<title>订单分割</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link type="text/css" rel="stylesheet" href="${staticPath}/layui/css/layui.css">	
		<link type="text/css" rel="stylesheet" href="${staticPath}/layui/modules/css/task.css">
		<link type="text/css" rel="stylesheet" href="${staticPath}/layui/modules/css/common.css">
		<style>
			td{ text-align:center;}
		</style>
	</head>
	<body style="padding:0 30px;">
	    <blockquote class="layui-elem-quote" style=" border-left: 0px solid #FFFFFF; background-color: #FFFFFF">
	        <img src="${staticPath}/layui/modules/images/shop/team.png" style="margin-left: -25px;"> 商户个人中心
	    </blockquote>
	    <blockquote class="layui-elem-quote">
			订单分割
	    </blockquote>
	    <div class="task_main clearall">
	        <ul class="task_nav clearall">
	            <li>
	                <div class="layui-btn-group" id="search-group">
	                  <button class="layui-btn navon" id="searchAll">全部</button>
	                  <button class="layui-btn" id="searchPC">PC端</button>
	                  <button class="layui-btn" id="searchAPP">APP端</button>
	                </div>
	            </li>
	            <li>
					<input type="text" class="task-search" placeholder="店铺名称|商品名称|SKU" id="task-search"/>
					&nbsp;&nbsp;
					<button class="layui-btn layui-btn-normal" id="search">查询</button>
				</li>
	            <li class="li-right">
	                <button class="layui-btn layui-btn-normal" id="split_task">拆分订单</button>
					<button class="layui-btn layui-btn-normal" id="delete_task">删除任务</button>
	            </li>
	        </ul>
	        <ul class="order-nav" id="order-nav">
	           
	        </ul>
		    <table class="layui-table" id="task-order-list" lay-skin="nob">
		      <thead >
		        <tr>
		          <th style="border-left:2px solid #2b90fe;">
		          	<input type="checkbox" lay-skin="primary" lay-filter="layTableAllChoose">序号
		          </th>
				  <th >主商品</th><th style="text-align:center;">操作时间</th><th style="text-align:center;">数量</th><th style="text-align:center;">单价</th><th>客单价备注</th>
			      <th style="text-align:center;">关键词1</th><th style="text-align:center;">关键词2</th><th style="text-align:center;">关键词3</th><th style="text-align:center;">关键词4</th><th style="text-align:center;">关键词5</th>
				  <th style="text-align:center;">筛选条件</th>
				  <th style="text-align:center;">城市合伙人</th>
		        </tr>
		      </thead>
		      <tbody id="tbody">
		      </tbody>
		    </table>
		    <div id="page"></div>
		</div>
		<script src="${staticPath}/layui/layui.js"></script>
		<script>
            layui.use(['laypage','jquery','layer','laytpl','form','laydate'], function(){
                var laypage = layui.laypage,$ = layui.jquery,layer = layui.layer,laytpl = layui.laytpl,form = layui.form,laydate = layui.laydate;
                var param = {
                    'queryFields': 'id,shopName,price,title,sku,type,createDate,orderCount,buyCount,keyword,keyword2,keyword3,keyword4,keyword5,remarks,basePrice,commissionPrice,totalPrice,imgUrl,offerLink,userName,',
                    'page.size':5,
                    'page.pn':1,
                    'order':'asc',
                    'query.status||eq':1
                }
                renderTable(param);
                function renderTable(param){
                    layer.load(1);
                    $.ajax({
                        url: '${adminPath}/client/split/ajaxList',
                        data:param,
                        type: "POST",
                        dataType: "JSON",
                        success: function(data){
                            layer.closeAll('loading');
                            laypage.render({
                                elem: 'page'
                                ,count: data.total
                                ,limit: param['page.size']
                                ,limits:[5,10,15,20]
                                ,curr: param['page.pn']
                                ,theme: '#1E9FFF'
                                ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
                                ,jump: function(obj,first){
                                    param['page.pn']=obj.curr
                                    $("input[lay-filter=layTableAllChoose]").removeAttr("checked");
                                    //首次不执行
                                    if(!first){
                                        renderTable(param);
                                    }
                                }
                            });
                            var getTpl = table.innerHTML,view = document.getElementById('tbody');
                            laytpl(getTpl).render(data, function(html){
                                view.innerHTML = html;
                            });
                            var rows = {};
                            $.each(data.results, function(index, item){
                                rows[item.id]=item;
                            });
                            $("#tbody").data("rows",rows);
                        },
                        error: function () {
                            layer.closeAll('loading');
                            layer.msg("未知错误，请联系管理员！",{icon: 2});
                        }
                    });
                }

                $("#split_task").bind({
                    click:function(){
                        layer.confirm('确认拆分？', {
                            btn: ['确定','取消'] //按钮
                        }, function(){
                            layer.load(1);
                            $.ajax({
                                url: '${adminPath}/client/split/split',
                                type: "POST",
                                dataType: "JSON",
                                success: function(result){
                                    if(result.ret==0){
                                        layer.alert(result.msg, {icon: 0, title:'提示',end: function(){
                                                layer.closeAll();
                                                renderTable(param);
                                            }});
                                    }else{
                                        layer.alert(result.msg, {icon: 0, title:'警告'});
                                    }

                                },
                                error: function () {
                                    layer.msg("未知错误，请联系管理员！",{icon: 2});
                                }
                            });
                        }, function(){

                        });
                    }
                });

                $("#searchAll").bind({
                    click:function(){
                        $("#search-group button").attr("class","layui-btn");
                        $(this).attr("class","layui-btn navon");
                        delete param['query.type||eq'];
                    }
                });
                $("#searchPC").bind({
                    click:function(){
                        $("#search-group button").attr("class","layui-btn");
                        $(this).attr("class","layui-btn navon");
                        param['query.type||eq'] = 1;
                    }
                });
                $("#searchAPP").bind({
                    click:function(){
                        $("#search-group button").attr("class","layui-btn");
                        $(this).attr("class","layui-btn navon");
                        param['query.type||eq'] = 0;
                    }
                });
                $("#search").click(function(){
                    var val=$("#task-search").val();
                    if(val==""){
                        delete param['query.groupSearch||custom'];
                    }else{
                        param['query.groupSearch||custom']=val;
                    }
                    renderTable(param);
                });

                $("input[lay-filter=layTableAllChoose]").bind({
                    change:function(){
                        if($(this).is(':checked')){
                            $("input[name=layTableCheckbox]").prop("checked",true);
                        }else{
                            $("input[name=layTableCheckbox]").removeAttr("checked");
                        }
                    }
                });
                $("#tbody").on('change', "input[name=layTableCheckbox]",function(){
                    var check = true;
                    $.each($("input[name=layTableCheckbox]"),function(i,obj){
                        if(!$(obj).is(':checked')){
                            check=false;
                        }
                    })
                    if(check){
                        $("input[lay-filter=layTableAllChoose]").prop("checked",true);
                    }else{
                        $("input[lay-filter=layTableAllChoose]").removeAttr("checked");
                    }
                });
                $("#delete_task").bind({
                    click:function(){
                        layer.confirm('将要删除所有任务，请确认？', {
                            btn: ['确定','取消'] //按钮
                        }, function(){
                            layer.load(1);
                            $.ajax({
                                url: '${adminPath}/client/split/delete',
                                type: "POST",
                                dataType: "JSON",
                                success: function(result){
                                    layer.closeAll('loading');
                                    if(result.ret==0){
                                        layer.alert(result.msg, {icon: 0, title:'提示',end: function(){
                                                renderTable(param);
                                            }});
                                    }else{
                                        layer.alert(result.msg, {icon: 0, title:'警告'});
                                    }

                                },
                                error: function () {
                                    layer.closeAll('loading');
                                    layer.msg("未知错误，请联系管理员！",{icon: 2});
                                }
                            });
                        }, function(){

                        });
                    }
                })
			});

		</script>
		<script id="table" type="text/html">
			{{#  layui.each(d.results, function(index, item){ }}
			<tr>
				<td><input type="checkbox"  lay-skin="primary" name="layTableCheckbox" value="{{item.id}}">{{index+1}} </td>
				<td class="goods">
					<img src="{{item.imgUrl}}" />
					<ul>
						<li class="dp_name" title="{{item.userName}}">客户名称：{{item.userName}}</li>
						<li class="dp_name" title="{{item.shopName}}">店铺名称：{{item.shopName}}</li>
						<li>金额：<span>￥{{item.price}}</span></li>
						<li class="dp_name" title="{{item.title}}">产品名称：{{item.title}}</li>
					</ul>
				</td>
				<td>{{item.createDate.substring(0,10)}}</td>
				<td>{{item.orderCount}}</td>
				<td>{{item.price}}</td>
				<td>{{item.title}}</td>
				<td>{{item.keyword}}</td>
				<td>{{item.keyword2}}</td>
				<td>{{item.keyword3}}</td>
				<td>{{item.keyword4}}</td>
				<td>{{item.keyword5}}</td>
				<td>{{item.offerLink}}</td>
				<td>{{item.remarks}}</td>
			</tr>
			{{#  }); }}
			{{#  if(d.results.length === 0){ }}
			<div class="layui-table-body layui-table-main">
				<div class="layui-none">无数据</div>
			</div>
			{{#  } }}
		</script>

	</body>
</html>